var superagent = require('superagent');
var cheerio = require('cheerio');
require('superagent-proxy')(superagent);
let url = 'https://m.amap.com/detail/index/poiid=B0FFIPJE9Z'  // 饸饹面
let sss = 'https://surl.amap.com/4kS7TFI1Mj'  // 饸饹面

function getMapHtml1(res, webUrl = "") {
  // webUrl='https://surl.amap.com/4kS7TFI1Mj'
  // webUrl='https://www.amap.com/place/B0FFIPJE9Z'
  webUrl = 'https://m.amap.com/search/mapview/poiid=B0FFIPJE9Z'
  // webUrl='https://m.amap.com/detail/index/poiid=B0FFIPJE9Z'
  superagent.get(webUrl).end(function (err, sres) {
    let result = {}
    if (err) result.error = err
    console.log("sres.text", sres.text)
    let $ = cheerio.load(sres.text);
    let html = $('body').html()
    // console.log("html", html)
    let name1 = $('.pDetail_header_title').html()
    //console.log("name1",name1)
    let name2 = $('.detail_title').html()
    //console.log("name2",name2)
    let warnning = $('div.warnning-text').html()
    //console.log("warnning",warnning)
    let poiname = $('h3.poiname').html()
    //console.log("poiname",poiname)
    let common_bottom = $('div.common_bottom').html()
    console.log("common_bottom", common_bottom)
    result.name = name1 || name2
    res.json(result)  //返回json数据
    return result
  })
}

function getMapHtml(res, webUrl = "") {
  // webUrl = 'https://blog.csdn.net/a_yue10/article/details/107525349'
  webUrl = 'https://m.amap.com/detail/index/poiid=B0FFIPJE9Z'
  //ID查询
  // var proxy = 'http://222.74.73.202';
  let proxy = '';

  superagent.get(webUrl)
      // .proxy(proxy)
      .end(function (err, sres) {
        let result = {}
        if (err) result.error = err
        // console.log("sres.text", sres.text)
        let $ = cheerio.load(sres.text);
        let body = $('body').text()
        result.body = body
        res.json(result)  //返回json数据
        return result
      })
}

module.exports = {
  getMapHtml
}
